<script setup>
import * as THREE from 'three'
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls'
import {ref,onMounted} from 'vue'
let firstThree = ref()
const scene = new THREE.Scene()

// const geometry = new THREE.BoxGeometry(100,100,100)
const geometry = new THREE.SphereGeometry(50,6,5)

let vertor = new THREE.Vector3(100,200,100)
console.log(vertor)

const metaerial = new THREE.MeshBasicMaterial({
  color:0x00ffff,
  side:THREE.DoubleSide,
  wireframe:true
})

const line = new THREE.Mesh(geometry, metaerial); 
line.position.set(0,0,0)
scene.add(line)


const width = window.innerWidth;
const height = window.innerHeight;

const camera = new THREE.PerspectiveCamera(100,width/height,1,8000)
camera.position.set(100,100,200)
camera.lookAt(0,0,0) 

const renderer = new THREE.WebGLRenderer();
renderer.setSize(width,height)
renderer.render(scene,camera)

const controls = new OrbitControls(camera,renderer.domElement)
controls.addEventListener("change",function(){
  // 重新渲染，必须有这步操作，否则数据改变，但无法看到
  renderer.render(scene,camera)
})
onMounted(()=>{
  document.getElementById("firstThree").appendChild(renderer.domElement)
})

</script>

<template>
  <div id="firstThree" ref="firstThree"></div>
</template>

<style scoped>
  #firstThree{
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    position: absolute;
  }
</style>
